package com.atguigu.spzx.manager.service.impl;


import com.atguigu.spzx.manager.mapper.SysRoleMapper;
import com.atguigu.spzx.manager.service.SysRoleService;
import com.atguigu.spzx.model.dto.system.SysRoleDto;
import com.atguigu.spzx.model.dto.system.SysUserDto;
import com.atguigu.spzx.model.entity.system.SysRole;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SysRoleServiceImpl implements SysRoleService {
    @Autowired
    private SysRoleMapper sysRoleMapper ;
    @Override
    public PageInfo<SysRole> findByPage(String rolename, Integer pageNum, Integer pageSize) {

            PageHelper.startPage(pageNum , pageSize) ;
            List<SysRole> sysRoleList = sysRoleMapper.findByPage(rolename);
            PageInfo<SysRole> pageInfo = new PageInfo(sysRoleList) ;
            return pageInfo;
    }

    @Override
    public void saveSysRole(SysRole sysRole) {
        sysRoleMapper.insertSysRole(sysRole);
    }

    @Override
    public void updateSysRole(SysRole sysRole) {
        sysRoleMapper.updateSysRole(sysRole);
    }

    @Override
    public void removeById(Integer id) {
        sysRoleMapper.deleteById(id);
    }

    @Override
    public Map<String , Object> findAll(Long userId) {
        Map<String , Object> resultMap = new HashMap<>() ;
        resultMap.put("allRolesList" , sysRoleMapper.selectAll()) ;
        resultMap.put("sysUserRoles", sysRoleMapper.selectByUserId(userId));
        return resultMap;
    }
}
